﻿using System;
using System.Collections.Generic;
using Core;

namespace DataAccess
{
    public class SanPham_Info
    {
        // Các thuộc tính của lớp 
        public int ID { get; set; }
        public int IDDanhMuc { get; set; }
        public string TenSanPham { get; set; }
        public string MoTa { get; set; }
        public string ChiTiet { get; set; }
        public double GiaHienTai { get; set; }
        public double GiaCu { get; set; }
        public string URLHinhAnh { get; set; }
        public int LaSPMoi { get; set; }
        public string NgayDang { get; set; }
        public string NhaSanXuat { get; set; }
        public string XuatXu { get; set; }
        public bool HoatDong { get; set; }

        public static List<SanPham_Info> SanPhams_ChonTatCa()
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPhams_ChonTatCa"));
        }

        //lấy tất cả các sản phẩm có ID danh mục
        public static List<SanPham_Info> SanPhams_ChonSPTheoDM(int IDDanhMuc)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPhams_ChonSPTheoDM", IDDanhMuc));
        }
        //lấy tất cả các sản phẩm có trong danh mục gôc
        public static List<SanPham_Info> SanPham_LayTheoDanhMucCha(int IDDanhMuc)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_LayTheoDanhMucCha", IDDanhMuc));
        }
        public static List<SanPham_Info> SanPham_ChonSPCungLoai(int soluong, int IDdanhmuc, int ID)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_ChonSPCungLoai", soluong, IDdanhmuc, ID));
        }


        public static SanPham_Info SanPham_Chon(int ID)
        {
            return CBO.FillObject<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_Chon", ID));
        }


        public static List<SanPham_Info> SanPham_LayTenDM(int IDDanhMuc)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_LayTenDM", IDDanhMuc));
        }

        public static bool SanPham_Them(int IDDanhMuc, string TenSanPham, string MoTa, string ChiTiet, string GiaHienTai,
                               string GiaCu, string NhaSanXuat, string XuatXu, string URLHinhAnh, int LaSPMoi, string NgayDang, bool HoatDong)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_SanPham_Them", IDDanhMuc, TenSanPham, MoTa, ChiTiet, GiaHienTai, GiaCu, NhaSanXuat, XuatXu, URLHinhAnh, LaSPMoi, NgayDang, HoatDong);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool SanPham_CapNhat(int ID, int IDDanhMuc, string TenSanPham, string MoTa, string ChiTiet,
                                  string GiaHienTai, string GiaCu, string NhaSanXuat, string XuatXu, string URLHinhAnh, int LaSPMoi,
                                  string NgayDang, int HoatDong)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_SanPham_CapNhat", ID, IDDanhMuc, TenSanPham, MoTa, ChiTiet,
                                                                  GiaHienTai, GiaCu, NhaSanXuat, XuatXu, URLHinhAnh, LaSPMoi,
                                                                  NgayDang, HoatDong);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool SanPham_Xoa(int ID)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("sp_SanPham_Xoa", ID);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool SanPham_CapNhatHoatDong(int ID, bool status)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("sp_SanPham_CapNhatHoatDong", ID, status);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static List<SanPham_Info> SanPham_ChonTheo(string option)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_ChonTheo", option));
        }

        public static List<SanPham_Info> TimKiem(string key)
        {
            string key2 = "%" + key + "%";
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_TimKiem", key2));

        }

        public static List<SanPham_Info> GetHot()
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("Products_GetHot"));
        }

        public static List<SanPham_Info> SanPham_ChonSPMoi()
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("sp_SanPham_ChonSPMoi"));
        }

        public static List<SanPham_Info> GetSaLe(bool khuyenmai)
        {
            return CBO.FillCollection<SanPham_Info>(DataProvider.Instance.ExecuteReader("Products_GetSaLe", khuyenmai));
        }
    }
}